<template>
  <div class="menuOperation">
    <t-poptip v-if="!auth.STATE" confirm placement="top" title="确认启用状态吗？" @on-ok="modifyState">
      <t-tooltip content="启用" placement="top">
        <t-icon type="play-circle-outline"></t-icon>
      </t-tooltip>
    </t-poptip>
    <t-poptip v-else confirm placement="top" title="确认禁用状态吗？" @on-ok="modifyState">
      <t-tooltip content="禁用" placement="top">
        <t-icon type="pause-circle-outline"></t-icon>
      </t-tooltip>
    </t-poptip>
    <t-tooltip ref="tooltip" content="编辑" placement="top">
      <t-icon type="border-color" @click.native="edit"></t-icon>
    </t-tooltip>
    <t-poptip confirm placement="top" title="确认删除这条内容吗？" @on-ok="deleteConfirm">
      <t-tooltip content="删除" placement="top">
        <t-icon type="delete"></t-icon>
      </t-tooltip>
    </t-poptip>
  </div>
</template>
<script>
export default {
  props: {
    auth: {
      type: Object,
      default: () => {}
    }
  },
  data() {
    return {

    }
  },
  methods: {
    edit() {
      this.$refs.tooltip.visible = false
      this.$router.push('/usermanage/auth/editEntityAuth/' + this.auth.ID)
    },
    // 修改菜单权限状态
    modifyState() {
      this.http.$http.post(this.services.MODIFY_AUTH_STATE, {
        bo: 'user',
        bc: 'USER_FUNCTION',
        upd_value: JSON.stringify({
          STATE: this.auth.STATE === 1 ? 0 : 1
        }),
        condition: JSON.stringify({
          ID: this.auth.ID
        })
      }).then(res => {
        if (res.data.CODE === 0) {
          this.$Message.success('菜单权限状态更改成功')
          this.$emit('deleteSuccess')
        } else {
          this.$Message.success('菜单权限状态更改失败')
        }
      })
    },
    // 确定删除
    deleteConfirm() {
      this.http.$http.post(this.services.DELETE_MENU_AUTH, {
        bo: 'user',
        bc: 'USER_FUNCTION',
        validation_method: 'com.wframe.usermanager.services.valid.FuncDeleteValid',
        condition: JSON.stringify({
          ID: this.auth.ID
        })
      }).then(res => {
        if (res.data.CODE === 0) {
          this.$Message.success('删除成功')
          this.$emit('deleteSuccess')
        } else {
          this.$Message.danger('删除失败')
        }
      })
    }
  }
}
</script>
<style lang="scss" scoped>
.menuOperation {
  i {
    cursor: pointer;
    margin-right: 10px;
    font-size: 16px;
  }
  .aid-play-circle-outline {
    color: #32cf9a;
  }
  .aid-pause-circle-outline {
    color: #ff6363;
  }
}
</style>

